package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.ReportUploadMapper;
import com.itheima.pojo.ReportUpload;
import com.itheima.service.ReportUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 体检报告上传服务
 */
@Service(interfaceClass = ReportUploadService.class)
@Transactional
public class ReportUploadServiceImpl implements ReportUploadService {

    @Autowired
    private ReportUploadMapper reportUploadMapper;

    @Override
    public PageResult findByPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        List<ReportUpload> list = reportUploadMapper.selectByCondition(queryPageBean.getQueryString());
        PageInfo<ReportUpload> pageInfo = new PageInfo<ReportUpload>(list);
        return new PageResult(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public void add(ReportUpload reportUpload) {
        reportUploadMapper.add(reportUpload);
    }

    @Override
    public void deleteById(Integer id) {
        reportUploadMapper.deleteById(id);
    }

    @Override
    public void upload(Integer id) {
        reportUploadMapper.changeReportStatusById(id);
    }
}
